//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<colorbuf.h>
///	@path	~/src/graphics/ximage/
///	@date	2008/03/31
///	@desc	Color buffer for image composition.

#pragma once

#include "xeres.h"

#include "lib/math/pair.h"
#include "lib/math/color.h"

namespace xeres {

	/*! 
		\class	ColorBuf
		\brief
	*/
	class ColorBuf
	{
	public:

		/// \name Constructor & Destructor
		//@{

		/// \ctor
		ColorBuf( size_t width , size_t height );

		/// \dtor
		~ColorBuf( void );

		//@}

	public:

		/// \name Attribute
		//@{

		/// \brief Color buffer width.
		size_t width( void ) const { return m_width; }

		/// \brief Color buffer height.
		size_t height( void ) const { return m_height; }

		//@}

		/// \name Color Buffer Operator
		//@{

		/// \brief Clear buffer with (0,0,0,0).
		void Clear( void );

		/// \brief Clear buffer.
		void Clear( const PackColor4& color );

		/// \brief Composite target buffer.
		void Composite( const ColorBuf& overlay , const Pair<int>& pos = Pair<int>(0,0) );

		/// \brief Blend 2 buffers in 1.
		void Blend( const ColorBuf& a , const ColorBuf& b , const Pair<int>& pos = Pair<int>(0,0) );

		/// \brief Blend buffer with alpha.
		void Blend( const ColorBuf& a , const PackColor4& alpha , const Pair<int>& pos = Pair<int>(0,0) );

		/// \brief Write target buffer.
		void Write( const ColorBuf& target , const Pair<int>& pos = Pair<int>(0,0) );

		/// \brief Invert buffer color.
		void InvertColor( bool with_alpha = false );

		//@}

	private:

		//@ data
		size_t		m_width;
		size_t		m_height;

		uint32 *	m_buf;
	};

} // namespace xeres
